#include<stdio.h>
#include<unistd.h>
#include<pthread.h>
#include<sys/types.h>
void Print(char*str)
{
    printf("%p：i am a %s\n",pthread_self(),str);
}
void* thread_entry(void*arg)
{
  sleep(4);
  printf("%p：i am child thread:%s\n",pthread_self(),arg);
  pthread_exit("over");
  return NULL;
}
int main()
{
  //tid用于接收线程id
  pthread_t tid;
  char *arg="hello bit";
  int ret=pthread_create(&tid,NULL,thread_entry,(void*)arg);
  //如果返回值为0，则说明线程创建成功，失败则返回非0值
  if(ret!=0)
  {
    perror("pthread error");
    return -1;
  }
  sleep(5);
  printf("%p\n",tid);
  void*retval;
  ret=pthread_join(tid,&retval);
  if(ret!=0)
  {
    printf("pthread_join error\n");
    return -1;
  }
  printf("%s\n",retval);
  Print("main thread");
  sleep(5);
  printf("main over\n");
  return 0;
}
